#include "FakeMulticastSender.h"
#include <fstream>

FakeMulticastSender::FakeMulticastSender(void) : _fin("./resources/FakeMulticastSender/satlocation.txt")
{
	_satLocation.mesg_head = 100;
}

FakeMulticastSender::~FakeMulticastSender(void)
{
	_fin.close();
}

bool FakeMulticastSender::initPlugin()
{
	if (_fin)
	{
		this->start();
		return true;
	}
	else
	{
		return false;
	}
}

void FakeMulticastSender::run()
{
	while (true)
	{
		sendMuticast();
		PosixThread::msleep(10);
	}
}

void FakeMulticastSender::sendMuticast()
{
	if (_fin.eof()) { return; }

	_fin >> _satLocation.num
		 >> _satLocation.name
		 >> _satLocation.x
		 >> _satLocation.y
		 >> _satLocation.z
		 >> _satLocation.lon
		 >> _satLocation.lat
		 >> _satLocation.alt
		 >> _satLocation.max_angle
		 >> _satLocation.min_angle
		 >> _satLocation.max_elev
		 >> _satLocation.min_elev;
	_satLocation.time = 0;
	_satLocation.flash = 0;

	NetworkCenter::inst()->multicast()->send((char*)&_satLocation, sizeof(SatLocation));
}
